import yaml

values = {
    "name": "Tom Smith",
    "age": 37,
    "spouse": {
        "name": "Jane Smith",
        "age": 25
    },
    "children": [
        {
            "name": "Jimmy Smith",
            "age": 15
        },
        {
            "name": "Jenny Smith",
            "age": 12
        }
    ]
}

values2 = [
    "坚果",
    "盖伦",
    {
        "name": "jeff",
        "pwd": "123456"
     }
]

# # 将字典数据转为yaml文件格式
# print(yaml.dump(values))
# # 将字典数据转为yaml文件格式，并写入到文件中
# with open('.\demo08.yaml', 'w', encoding='utf-8') as f:
#     yaml.dump(values, f)
# 将组数据以多端yaml文件的形式写入到一个yaml文件中
with open('.\demo09.yaml', 'w', encoding='utf-8') as f:
    yaml.dump_all([values, values2], f, allow_unicode=True)